package com.restaurant.web.android.service;

import java.io.IOException;
import java.util.ArrayList;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.restaurant.domain.Menuorder;
import com.restaurant.domain.Tables;
import com.restaurant.service.MenuorderService;
import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.io.xml.DomDriver;

@Component
@RequestMapping("/resumemenuorderservice.do")
public class ResumeMenuorderService {
	
	@Autowired
	private MenuorderService objMenuorderService;
	
	@RequestMapping(method=RequestMethod.POST)
	public void resumeMenuorderServicePOSTRequest(HttpServletRequest request, HttpServletResponse response){
		
		XStream objXStream = new XStream(new DomDriver());
		objXStream.alias("Menuorder", Menuorder.class);
		objXStream.alias("ArrayList", ArrayList.class);
		
		Tables tables = (Tables) objXStream.fromXML(request.getParameter("Tables"));
		ArrayList<Menuorder> listMenuorders = null;
		try {
			listMenuorders = (ArrayList<Menuorder>) objMenuorderService.loadByHql("FROM Menuorder m where m.isdeleted = false AND m.tableorder.tables.tableID = "+ tables.getTableID());
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		try {
			response.getWriter().print(objXStream.toXML(listMenuorders));
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}
